package com.ycwl.freetv.utils;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;

public class Http {
    public static String doGet(String url, HashMap<String,String> hashMap,HashMap<String,String> params) {
        String res = "";
        HttpURLConnection connection = null;
        StringBuffer sb = null;
        InputStream is = null;
        BufferedReader br = null;
        try {
            URL url1 = new URL(url);
            connection = (HttpURLConnection) url1.openConnection();
            connection.setRequestMethod("GET");
            connection.setConnectTimeout(10000);
            connection.setReadTimeout(60000);

            connection.connect();
            if (connection.getResponseCode() == 200 || connection.getResponseCode() == 206) {
                is = connection.getInputStream();
                br =  new BufferedReader(new InputStreamReader(is,"UTF-8"));
                sb = new StringBuffer();
                String tem = null;
                while (( tem = br.readLine()) != null) {
                    sb.append(tem);
                }
                res = sb.toString();
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            connection.disconnect();
            if (br != null) {
                try {
                    br.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            if (is != null) {
                try {
                    is.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return res;
    }
}
